# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=automake1.6
pkgver=1.6.3
pkgrel=2
pkgdesc="A GNU tool for automatically creating Makefiles"
arch=('any')
license=('GPL')
url="https://www.gnu.org/software/automake"
groups=('base-devel')
depends=('perl' 'bash')
makedepends=('autoconf')
checkdepends=('dejagnu' 'python2')
install=automake.install
source=(https://ftp.gnu.org/gnu/automake/automake-${pkgver}.tar.bz2
        automake1.6-add-dirlist-support.patch
        automake1.6-accomodate-newer-autoconf.patch
        automake1.6-documentation.patch
        automake1.6-avoid-autoreconf.patch
        automake-1.7-msys2.patch)
sha256sums=('0dbafacaf21e135cab35d357a14bdcd981d2f2d00e1387801be8091a31b7bb81'
            '4fbd10aa0efe328f1a1d9cbc8a5686113eaee182cd84ac80ae000272ac7bf249'
            'e504a4148ce10aa598728d42a50e10fb4fe70dd8eabc17f1dab97c3aee965649'
            'd531bb3c82cef450e63d8cf5b14ef53094b21a760017ee5091fc509634bf1f31'
            '27ed8ecef2b42aac601faa1ab69a9f673d018db41dc3f0128fd4861465193056'
            'e3d7a2ce2942b341dfda226a38e814e2632600ac4be5044fda0c579420e54094')

prepare() {
  cd ${srcdir}/automake-${pkgver}

  patch -p2 -i ${srcdir}/automake1.6-add-dirlist-support.patch
  patch -p2 -i ${srcdir}/automake1.6-accomodate-newer-autoconf.patch
  patch -p2 -i ${srcdir}/automake1.6-documentation.patch
  patch -p1 -i ${srcdir}/automake1.6-avoid-autoreconf.patch
  patch -p1 -i ${srcdir}/automake-1.7-msys2.patch
}

build() {
  cd ${srcdir}/automake-${pkgver}
  ./configure --prefix=/usr
  make

  (makeinfo -I ${srcdir}/automake-${pkgver} -o automake1.6.info automake.texi)
}

check() {
  cd ${srcdir}/automake-${pkgver}

  # expect 2 failures due to perl-5.18 incompatibility
  make -k check || true
}

package() {
  cd ${srcdir}/automake-${pkgver}
  make DESTDIR=${pkgdir} install

  mv ${pkgdir}/usr/info ${pkgdir}/usr/share/

  # install the 1.6 versioned info files
  for f in `find ${pkgdir}/usr/share/info -name "*.info*"` ; do
    rm -f ${f}
  done
  for f in `find ${srcdir}/automake-${pkgver} -name "*.info*"` ; do
    bf=`basename $f`
    cp $f ${pkgdir}/usr/share/info/
  done

  # remove the unversioned executables
  rm -f ${pkgdir}/usr/bin/automake ${pkgdir}/usr/bin/aclocal

  # remove the unversioned man pages
  rm -f ${pkgdir}/usr/share/man/man1/automake.1
  rm -f ${pkgdir}/usr/share/man/man1/aclocal.1

  # remove the unversioned info files
  rm -f ${pkgdir}/usr/share/info/automake.info*

  rm -rf ${pkgdir}/usr/share/doc
}
